$(function() {
	var $modal = $('#my-modal-loading');
	var page = 1;
	var jsonStr;
	var ary = new Array();
	$("#create_btn").click(function(){
		location.href = "http://yx.fxtourong.com/V1/Goods/create_query.html";
	});
	$("#header_create").click(function(){
		location.href = "http://yx.fxtourong.com/V1/Goods/create_query.html";
	});
	$("#foodimg3").click(function(){
		location.href = "mine3.html";
	});
	$("#foodimg2").click(function(){
		location.href = "queryfind.html";
	});
	$("#add_query").click(function(){
		location.href = "allquery.html";
	});
	$("#div_search").click(function(){
		var text = $("#search_text").val();
		localStorage.setItem("search_text", text);
		location.href = "searchquery.html";
//		new Toast({context:$('body'),message:'Toast效果显示'}).show();
	});
	$modal.modal();
	getData();
		
	function getData(){
		$.ajax({
			type: "POST",
			url: "http://yx.fxtourong.com/V1/Circle/myCircleList",
			data: {
				token : localStorage.getItem("token"),
				page: page
			},
			dataType: "json",
			success: function(data) {
				$modal.modal('close');
				var code = data.code;
				console.log("code:" + data.code);
				if(code == "1") {
					isFirst = true;
					if(page == 1){
//						$("#header_create").css("visibility", "visible");
//						$("#title_div").css("display", "block");
					}
					jsonStr = data.data;
					if(page == 1){
						
					}
					for(var i = 0; i<jsonStr.length; i++){
						var industry = jsonStr[i];
						ary.push(industry);
						var is_pay = industry.is_pay;
						console.log("qqqqqq:" + is_pay);
						var price = "免费";
						if(is_pay == "0"){
							price = "免费";
						} else {
							price = industry.price + "元";
						}
						var is_pwd = industry.is_encrypt;
						var pwd = "免密";
						if(is_pwd == "0"){
							pwd = "免密";
						} else {
							pwd = "加密";
						}
						var juse = industry.type;
						var juseType = "我是圈主";
						if(juse == "1"){
							juseType = "普通圈友";
						} else if(juse == "2"){
							juseType = "我是管理员";
						} else if(juse == "3"){
							juseType = "我是圈主";
						}
//						overflow: hidden;white-space: nowrap;text-overflow: ellipsis;
						var timeStr = industry.created_time;
						$("#query_ul").append("<li class='am-g' style='border-bottom:1px solid #DEDEDE;border-top:0px solid #DEDEDE;padding-top:0px;margin-top:0px;margin-bottom:0px;' value='" + (((page-1) * 10) + i) + "' onclick=''>" + 
					        "<div class='am-u-sm-2 am-list-thumb'>" + 
					        "<img src='" + industry.cover + "' style='width: 50px;height: 50px;margin-left: 10px;display: inline;margin-top: 10px;margin-bottom: 10px;'/>" + 
					        "</div>" + 
					        "<div class='am-u-sm-10 am-list-main'>" + 
					            "<div class='am-list-item-hd' style='margin-top:6px;'><span style='font-size: 15px;margin-left:12px;'>" + industry.name + "</span>" + 
					            "</div>" +
					            "<div class='am-list-item-text' style='margin-top: 8px;'><span style='font-size: 16px;color: #B6940A;display:none;'>" + price + "</span>" +
					            "</div>" +
								"<div class='am-list-item-text' style='margin-top: 2px;'><span style='font-size: 14px;color: #BBBBBB;margin-left:12px;'>" + juseType + "</span>" + 
								"</div>" + "</div>" + 
								"<div class='am-u-sm-0 am-list-main'>" + 
					            "<div class='am-list-item-hd'>" +
					            	"<span style='font-size: 14px;color: #BBBBBB;float: right;margin-right: 10px;margin-top: 10px;display:none;'>" + timeStr + "</span>" +
					            	"<button value='" + industry.id + "' class='am-btn am-btn-secondary am-round' style='font-size: 12px;float:right;margin-right: 10px;margin-top:8px;display:none;'>" + "进圈" + "</button>" +
					            "</div>" +
								 "</div>" + 
								"</li>");
					}
				} else {
					$modal.modal('close');
					if(page == 1){
//						$("#header_create").css("visibility", "hidden");
//						$("#title_div").css("display", "block");
					}  
//					alert(data.message + "");
				}
			}
		});
	}
		
	$(document).on("click", "ul li", function() {
		var m = $(this).val();
		$(this).addClass('shit');
		//	var juse = ary[m].type;
		//	var juseType = "我是圈主";
		//	if(juse == "1") {
		//		juseType = "普通圈友";
		//	} else if(juse == "2") {
		//		juseType = "我是管理员";
		//	} else if(juse == "3") {
		//		juseType = "我是圈主";
		//	}
		localStorage.setItem("query_id", ary[m].id);
		localStorage.setItem("query_role", ary[m].type);
		location.href = "query_detail.html";
	});
	
	var isFirst = true;
	
	$(window).scroll(function() {
  
//	    if ($(document).scrollTop()<=0){
//	      alert("滚动条已经到达顶部为0");
//	    }
	  
	    if ($(document).scrollTop() >= ($(document).height() - $(window).height())) {
			if(isFirst){
				$modal.modal();
				isFirst = false;
				page = page + 1;
				getData();
			}
			
	    }
  	});
  	
});